﻿//双击事件
function CustomDbClick() {
    parent.closeWin(); //去掉双击功能
}

var IsPost = "N";
var Level = "0";
//获取自己信息
function GetCategory(ID) {
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=hrCoreEmpDataBase&condition=ID='" + ID + "'";
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");
        for (var o in list.rows) {
            //debugger;
            var t = list.rows[o].IsPost;
            if (typeof (t) != "undefined") {
                IsPost = t;
                var arrLevel = list.rows[o].SeqNo.split("-");
                Level = arrLevel.length;
            }
        }
    });
}


//新增分类
var fnAddClass = function () {
    //debugger;
    //alert("_key:" + _key + " _Caption:" + _Caption)
    var CategoryID = _key;
    if (CategoryID == null || CategoryID == "") {
        alert("请先选择上级分类！");
        return;
    }
    var CategoryName = _Caption;
    GetCategory(CategoryID);
    //alert("IsPost:" + IsPost + " Level:" + Level);
    //只有小于2级分类才可以分类
    if (Level>2) {
        alert("不可以分类!");
        return;
    }
    const_EditEntity = "hrCoreEmpDataBase";
    document.getElementById("dialog1_h").innerHTML = "新增分类";
    document.getElementById("EditUIWindow").src = "../Extend/AutoLoadForm.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&CategoryID=" + CategoryID + "&CategoryName=" + CategoryName + "&flag=Add";
    SetDWH(550, 480, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
    parent.NeedRefreshPage = this;
}

//保存成功回调
var CallBackParameter = function (obj) {
    //debugger;
    RefreshTreeData(obj.ClassName, obj.ID);
}

//修改分类
var fnEditCategory = function () {
    //debugger;
    //alert("_key:" + _key + " _Caption:" + _Caption)
    var CategoryID = _key;
    if (CategoryID == null || CategoryID == "") {
        alert("请先选择上级分类！");
        return;
    }
    var CategoryName = _Caption;
    const_EditEntity = "hrCoreEmpDataBase";
    document.getElementById("dialog1_h").innerHTML = CategoryName + "_修改";
    document.getElementById("EditUIWindow").src = "../Extend/AutoLoadForm.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&CategoryID=" + CategoryID + "&CategoryName=" + CategoryName + "&flag=Edit";
    SetDWH(550, 480, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}

//删除分类
var fnDelClass = function () {
    //debugger;
    //alert("_key:" + _key + " _Caption:" + _Caption)
    var CategoryID = _key;
    if (CategoryID == null || CategoryID == "") {
        alert("请选择要删除的分类！");
        return;
    }
    var CategoryName = _Caption;
    const_EditEntity = "hrCoreEmpDataBase";
    GetCategory(CategoryID);
    //只有小于2级分类才可以分类
    if (Level > 2) {
        alert("请选择要删除的分类!");
        return;
    }

    if (confirm("删除后将无法恢复,确定要删除吗?")) {
        YAHOO.util.Connect.asyncRequest('POST', "../EHR/workTimeAjax.aspx?flag=isdelCoreEmpClass" + "&id=" + CategoryID, {
            success: function (res) {
                try {
                    var str = res.responseText;
                    if (str == "1") {
                        deleteNode();
                    }
                    else if (str == "2") {
                        alert("有下级分类，不能删除！");
                        return;
                    }
                    else if (str == "3") {
                        alert("有引用了分类，不能删除！");
                        return;
                    }
                    else if (str == "-1" || str == "0") {
                        alert("删除失败！");
                        return;
                    }
                }
                catch (e) {
                    alert("删除失败：" + e.Message);
                    return;
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
                return;
            }
        }, null);
    }
}

//新增
var fnCustomAdd = function () {
    var CategoryID = _key;
    if (CategoryID == null || CategoryID == "") {
        alert("请选择二级分类！");
        return;
    }
    var CategoryName = _Caption;
    GetCategory(CategoryID);
    //alert("Level:" + Level);
    //只有小于2级分类才可以分类
    if (Level != 3) {
        alert("请选择二级分类!");
        return;
    }
    var DutyInfoID = null;
    var pagetitle = CategoryName + "_核心人才职务选择";
    var url = "../Extend/YUIDataTableList.aspx?entity=V_DatDutyInfo&order=DutyTypeName,SequenceNo&functionID=01B5D7A0-3439-4AED-A1FC-CA043A58B84C&CategoryID=" + CategoryID;
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, url);
}

//修改
var fnCustomEdit = function () {
    return;
}

//删除
var fnCustomDelete = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    //debugger;
    var list = this.mDataTable.getRecordSet()._records;
    var elist = [];
    dl = [];
    for (var i = 0; i < list.length; i++) {
        //this.getRecordSet()._records[0]._oData["BarItem"]
        if (list[i]._oData["iSun_Selected"] == true) {
            elist.push(list[i]._oData[const_entityID]);
            dl.push(list[i]._sId); //获取行ID；
        }
    }

    var id = record.getData(const_entityID);
    //第一步先删除相关的引用表信息、子表、主表
    YAHOO.util.Connect.asyncRequest('POST', "../EHR/workTimeAjax.aspx?flag=DelDatDutyInfo" + "&json=" + elist.join(","), {
        success: function (res) {
            try {
                var str = res.responseText;
                if (str == "1") {
                    //第二步
                    var list = mDataTable.getRecordSet()._records;
                    dl = [];
                    for (var i = 0; i < list.length; i++) {
                        if (list[i]._oData["iSun_Selected"] == true) {
                            dl.push(list[i]._sId); //获取行ID；
                        }
                        SaveUrl = "../Extend/AjaxData/DataSave.aspx?r=" + Math.random() + "&action=delete&entity=" + const_EditEntity + "&id=" + id;
                        YAHOO.example.container.dialog3.show();
                    }
                }
                else if (str == "-1") {
                    alert("此ID为空，删除失败！");
                    return;
                }
            }
            catch (e) {
                alert("删除失败：" + e.Message);
                return;
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
            return;
        }
    }, null);
}

//初始化
if (typeof ($) != "undefined") {
    $(document).ready(function () {


    });
}



